package si.feri;

import si.feri.kaca.IgralnaPovrsina;
import si.feri.kaca.Kaca;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

public class OknoKaca extends Activity implements OnClickListener{
        
	private LinearLayout igralnaPovrsinaLayout;
	private IgralnaPovrsina igralnaPovrsina;
	private TextView ime;
	private Kaca kaca = new Kaca();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.kaca);
	            
	             //ustvari gumb in vezes na njega klik
	    TextView levoGumb = (TextView)findViewById(R.id.Lgumb);
	    levoGumb.setOnClickListener(this);
	    
	    TextView desnoGumb = (TextView)findViewById(R.id.Dgumb);
	    desnoGumb.setOnClickListener(this);
	    		
	    ime = (TextView)findViewById(R.id.textView1);
	    
	    SharedPreferences settings = getSharedPreferences("nastavitve", 0);
	    String upIme = settings.getString("upIme", "");
	    ime.setText(upIme);
	    
	    //pridobimo okno za prikaz točk
	    TextView tockePrikaz = (TextView)findViewById(R.id.textViewTocke);
	    
	    
	    igralnaPovrsinaLayout = (LinearLayout)findViewById(R.id.LinearLayoutIgralnaPovrsina);
	    
	    //posredujemo to okno igralni površini
	    igralnaPovrsina = new IgralnaPovrsina(this, tockePrikaz, Float.valueOf(settings.getString("tezavnost", "1")), upIme);
	    igralnaPovrsinaLayout.addView(igralnaPovrsina, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
	    
    
    }

    public void onClick(View v) {
            // TODO Auto-generated method stub
            
            //uporaba tega Levega gumba
        if(v.getId() == R.id.Lgumb) {
                //pup up Nova Levo :D
                //Toast.makeText(this, "LEVO LEVO LEVO", Toast.LENGTH_LONG).show();
        		igralnaPovrsina.premakniLeviGumb();
        }
        //uporaba tega Desnega gumba 
        if(v.getId() == R.id.Dgumb) {
        		igralnaPovrsina.premakniDesniGumb();
        }
    }
    
    private void SavePreferences(String key, String value){
		SharedPreferences settings = getSharedPreferences("rezultati", 0);
	    SharedPreferences.Editor editor = settings.edit();
	    editor.putString(key, value);
	    editor.commit();
 }
    
    private void LoadPreferences(){
    	SharedPreferences settings = getSharedPreferences("nastavitve", 0);
        String upIme = settings.getString("upIme", "");
        ime.setText(upIme);
    }
    

}